/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.NoteManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.SQLException;
/*    */ import java.util.List;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONObject;
/*    */ 
/*    */ public class SearchAllNote extends AbstractAction
/*    */ {
/*    */   public SearchAllNote(AbstractHttpServlet servlet)
/*    */   {
/* 27 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 37 */     User user = super.getLoginUser(request);
/* 38 */     String key = Util.getURLParameter(request.getParameter("SearchKey"));
/* 39 */     int offset = Util.getURLIntParameter(request.getParameter("Offset"));
/*    */ 
/* 41 */     int totalPages = Util.getURLIntParameter(request
/* 42 */       .getParameter("TotalPages"));
/*    */ 
/* 44 */     response.setContentType("text/html;charset=utf-8");
/* 45 */     PrintWriter out = response.getWriter();
/* 46 */     JSONObject jsonObject = new JSONObject();
/*    */ 
/* 48 */     NoteManager manager = new NoteManager();
/*    */     try {
/* 50 */       int totalNums = 0;
/* 51 */       if (totalPages < 1) {
/* 52 */         totalNums = manager.searchTotalNum(user.companyId, key, 
/* 53 */           user.isAdmin, user.isGroupAdmin, user.groupId, 
/* 54 */           user.userId);
/* 55 */         totalPages = totalNums / 10;
/* 56 */         if (totalNums % 10 > 0) {
/* 57 */           totalPages++;
/*    */         }
/*    */       }
/* 60 */       List result = manager.search(user.companyId, 
/* 61 */         key, user.isAdmin, user.isGroupAdmin, user.groupId, 
/* 62 */         user.userId, offset, 10);
/* 63 */       jsonObject.put("error", "0");
/* 64 */       jsonObject.put("notes", result);
/* 65 */       jsonObject.put("totalNums", Integer.valueOf(totalNums));
/* 66 */       jsonObject.put("totalPages", Integer.valueOf(totalPages));
/*    */     } catch (DBException e) {
/* 68 */       jsonObject.put("error", "1");
/* 69 */       e.printStackTrace();
/*    */     } catch (SQLException e) {
/* 71 */       jsonObject.put("error", "1");
/* 72 */       e.printStackTrace();
/*    */     }
/* 74 */     out.println(jsonObject);
/* 75 */     out.flush();
/* 76 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.SearchAllNote
 * JD-Core Version:    0.6.1
 */